package leetcode.day_2020_12_21_12_28;

import java.util.Stack;

/**
 * 用栈实现队列
 */
public class L_232 {

}

class MyQueue {
    private Stack<Integer> s1, s2;

    /**
     * 初始化队列
     */
    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }
    /**
     * 入队
     */
    public void push(int x) {
        s1.push(x);
    }

    /**
     * 出队
     */
    public int pop() {
        peek();
        return s2.pop();
    }

    /**
     * 返回队头元素
     */
    public int peek() {
        if(s2.isEmpty()) {
            while (!s1.isEmpty()) {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    /**
     * 判断队列是否为空
     */
    public boolean empty() {
        if(s1.isEmpty() && s2.isEmpty()) {
            return true;
        } else{
            return false;
        }
    }
}
